package com.lcq.gulimall.order.service.impl;

import com.lcq.gulimall.order.entity.OrderEntity;
import com.lcq.gulimall.order.entity.PaymentInfoEntity;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;

import java.io.IOException;

@Service
@RabbitListener(queues = "hello-queue")
public class TestServiceImpl {
    @RabbitHandler
    public void handler1(Message message, OrderEntity orderEntity, Channel channel){
        System.out.println("orderEntity id:"+orderEntity.getId()+"name:"+orderEntity.getMemberUsername());
        try {
            //channel.basicNack(message.getMessageProperties().getDeliveryTag(),false,true);
            //channel.basicReject(message.getMessageProperties().getDeliveryTag(),true);
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @RabbitHandler
    public void handler2(Message message, PaymentInfoEntity paymentInfoEntity){
        System.out.println("paymentInfoEntity id:"+paymentInfoEntity.getId()+"AlipayTradeNo:"+paymentInfoEntity.getAlipayTradeNo());
    }
}
